#!/bin/bash

jdk_dir=$1
priority=$2
#echo $jdk_dir

if [ -z "$jdk_dir" ]; then
    echo "jdk dir needed."
    exit 1
fi

if [ -z "$priority" ]; then
    echo "priority needed."
    exit 1
fi

## java ##
# sudo update-alternatives --install /usr/bin/java java $jdk_dir/bin/java $priority

## javaws ##
# update-alternatives --install /usr/bin/javaws javaws $jdk_dir/jre/bin/javaws $priority

## Install javac only if you installed JDK (Java Development Kit) package ##
# sudo update-alternatives --install /usr/bin/javac javac $jdk_dir/bin/javac $priority
# sudo update-alternatives --install /usr/bin/jar jar $jdk_dir/bin/jar $priority

## install all executable files in $jdk_dir/bin
for p in $jdk_dir/bin/*; do
    f=`basename $p`
    echo "sudo update-alternatives --install /usr/bin/$f $f $p $priorit"
    sudo update-alternatives --install /usr/bin/$f $f $p $priority
done

## Java Browser (Mozilla) Plugin 32-bit ##
# update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so libjavaplugin.so
$jdk_dir/jre/lib/i386/libnpjp2.so $priority

## Java Browser (Mozilla) Plugin 64-bit ##
echo "sudo update-alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so
libjavaplugin.so.x86_64 $jdk_dir/jre/lib/amd64/libnpjp2.so $priority"
sudo update-alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so
libjavaplugin.so.x86_64 $jdk_dir/jre/lib/amd64/libnpjp2.so $priority

